﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;

namespace JuCheap.Core.Data
{
    public class JuCoreDesignTimeDbContextFactory : IDesignTimeDbContextFactory<JuCheapContext>
    {
        public JuCheapContext CreateDbContext(string[] args)
        {
            var configuration = new ConfigurationBuilder()
                .SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "../JuCheap.Core.Web/"))
                .AddJsonFile("appsettings.json", optional: false)
                .Build();

            var builder = new DbContextOptionsBuilder<JuCheapContext>()
                .UseMySql(configuration.GetConnectionString("Connection_MySql"));

            return new JuCheapContext(builder.Options);
        }
    }
}
